<template>
	<view>
		<image class="head" src="@/static/hBg.png"></image>

		<uni-card>
			<view class="v_center" style="margin-top: 20rpx;">
				<view class="up_bottom" style="font-size: 36rpx;font-weight: 600;"
					v-if="data.stateName != null && stateCancel != data.stateName">核销码：{{data?data.number:'没有数据'}}
				</view>
				<image :class="data?(data.stateName == stateCancel ? 'img_w_h img_op':'img_w_h'):'img_w_h'"
					src="/static/eCode.png">
				</image>
			</view>
		</uni-card>
		<uni-card title="维修信息">
			<view class="flex"> <text>维修单号：</text> <text>{{data?data.id:'无'}}</text> </view>
			<view class="flex"> <text>维修状态：</text> <text>{{data?data.stateName:'无'}}</text> </view>
			<view class="flex"> <text>车主姓名：</text> <text>{{user?(user.sysUser?user.sysUser.nickName:'暂无'):'无'}}</text>
			</view>
			<view class="flex"> <text>联系方式：</text> <text>{{data?data.phone:'无'}}</text> </view>
			<view class="flex"> <text>维修方式：</text> <text>{{data?(data.type==0?'上门取车':'到店维修'):'无'}}</text> </view>
			<view class="flex" v-if="data.type==0"> <text>取车位置：</text> <text>{{data?data.address:'无'}}</text> </view>
			<view class="flex"> <text>预约日期：</text> <text>{{data?data.subscribeTime:'无'}}</text> </view>
			<view class="flex"> <text>提交日期：</text> <text>{{data?data.submitTime:'无'}}</text> </view>
		</uni-card>

		<uni-card title="车辆信息">
			<view class="flex"> <text>车辆类型：</text> <text>{{car?car.type:'暂无'}}</text> </view>
			<view class="flex"> <text>车牌号：</text> <text>{{car?car.carNumber:'暂无'}}</text> </view>
			<view>整车照片</view>
			<u-image width="200rpx" height="200rpx" :src="data.photo"></u-image>
			<view>维修部位照片</view>
			<view v-if="data != null && data.cheMaintainImages != null" class="flex" style="flex-wrap: wrap;">
				<view v-for="item in data.cheMaintainImages">
					<u-image width="190rpx" height="190rpx" :src="item.photo"></u-image>
				</view>
			</view>
			<view v-else style="margin-left: 50rpx;">暂无照片</view>
		</uni-card>

		<view class="footer" v-if="stateCancel != null && data.stateName != null">
			<u-button @click="cancel" style="width: 400rpx;" type="primary" shape="circle"
				:disabled="stateCancel == data.stateName">取消预约</u-button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: null,
				detailId: 'asf',
				isOutTime: false,
				data: '',
				user: null,
				car: null,
				// 维修状态列表
				stateList: null,
				stateCancel: '已取消',
				stateCancelId: -1
			}
		},
		onLoad(e) {
			console.log(e);
			if (e.id != null) {
				this.detailId = e.id
			}
			if (e.form != null) {
				this.form = JSON.parse(e.form)
			}
			// 获取维修状态列表
			this.getStateList()
			// // 获取维修信息
			// this.getMaintain()
			// 获取用户信息
			this.user = {
				id: uni.getStorageSync('userId')
			}
			this.getUser()
		},
		methods: {
			// 获取
			getMaintain() {
				let that = this
				this.$http({
					url: '/api/repair/maintain/' + that.form.id,
					method: 'GET',
					success(res) {
						console.log(res.data)
						if (res.data.code != 200) {
							return;
						}
						that.data = res.data.data
						// 获取车辆信息
						that.getCar()
						// 获取状态
						if (that.stateList != null) {
							for (let i of that.stateList) {
								if (i.dictValue == that.data.state) {
									that.data.stateName = i.dictLabel
									// console.log('维修信息：')
									// console.log(that.data)
									break
								}
							}
						}
					}
				})
			},
			// 获取用户信息
			getUser() {
				let that = this
				if (this.user != null && this.user.id != null) {
					this.$http({
						url: '/api/user/userr/getxiangxi/' + this.user.id,
						method: 'GET',
						success(res) {
							// console.log(res.data)
							that.user = res.data.data
							console.log('用户信息：' + that.user.id)
							console.log(that.user)
						}
					})
				}
			},
			// 取消预约
			cancel() {
				let that = this
				uni.showModal({
					title: '是否取消预约',
					success(res) {
						// 修改预约状态--取消
						if (res.confirm) {
							that.$http({
								url: '/api/repair/maintain',
								method: 'PUT',
								data: {
									id: that.form.id,
									state: that.stateCancelId,
								},
								success(res) {
									console.log(res.data)
									if (res.data.code == 200) {
										uni.showToast({
											title: '已取消预约',
											duration: 1500,
										})
										that.getMaintain()
									}
								}
							})

						}

					}
				})
			},
			// 获取状态列表
			getStateList() {
				let that = this
				this.$http({
					url: '/api/system/dict/data/type/maintain_state',
					method: 'GET',
					success(res) {
						console.log(res.data)
						if (res.data.code != 200) {
							return;
						}
						that.stateList = res.data.data
						for (let i of that.stateList) {
							if (i.dictLabel == that.stateCancel) {
								that.stateCancelId = i.dictValue
								break;
							}
						}
						// 获取维修信息
						that.getMaintain()
					}
				})
			},

			getCar() {
				let that = this
				this.$http({
					url: '/api/user/car/' + that.data.carId,
					method: 'GET',
					success(res) {
						console.log("车辆信息")
						console.log(res.data)
						that.car = res.data.data
					}
				})
			},

		}
	}
</script>

<style scoped lang="scss">
	.head {
		position: absolute;
		z-index: 0;
		width: 100%;
		margin-top: -50rpx;
	}

	.v_center {
		width: 600rpx;
		text-align: center;
	}

	.img_w_h {
		width: 150rpx;
		height: 150rpx
	}

	.img_op {
		opacity: 0.2;
	}

	.flex {
		display: flex;
		justify-content: space-between;
	}

	.footer {
		background-color: white;
		padding-top: 20rpx;
		height: 100rpx;
	}
</style>